package pe.gob.osinergmin.utils;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.List;

import pe.gob.osinergmin.bean.SupervisionMovil;
import pe.gob.osinergmin.bean.SupervisionMovilDetalleSCOP;

public class PuntoControlDetalleScopControl {

    private static final String PREFS_NAME ="detalleScopState";

    private static final String DETALLE_SCOP_LIST = "DETALLE_SCOP_LIST";

    private static final String SUPERVISION_SCOP = "SUPERVISION_SCOP";

    private SharedPreferences detalleScopControlPrefs;

    public PuntoControlDetalleScopControl(Context context) {
        this.detalleScopControlPrefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
    }

    public void saveDetalleScopList(SupervisionMovil supervisionMovil, List<SupervisionMovilDetalleSCOP> supervisionMovilDetalleSCOPList){
        SharedPreferences.Editor editor = detalleScopControlPrefs.edit();
        editor.putString(DETALLE_SCOP_LIST, PuntoControlUtils.convertFromListToJsonString(supervisionMovilDetalleSCOPList));
        editor.putString(SUPERVISION_SCOP, supervisionMovil.toString());
        editor.commit();
    }

    public List<SupervisionMovilDetalleSCOP> getDetalleScopList(){
        List detalleScopList = PuntoControlUtils.convertFromJsonStringToList(detalleScopControlPrefs.getString(DETALLE_SCOP_LIST,"[]"));
        return detalleScopList;
    }

    public SupervisionMovil getSupervisionMovil(){
        SupervisionMovil supervisionMovil = (SupervisionMovil)PuntoControlUtils.convertFromJsonStringToObject(detalleScopControlPrefs.getString(SUPERVISION_SCOP,""));
        return supervisionMovil;
    }

    public void clear(){
        SharedPreferences.Editor editor = detalleScopControlPrefs.edit();
        editor.clear();
    }
}
